
//
//  ForgetViewController.m
//  Travel assistant
//
//  Created by 王京 on 16/3/10.
//  Copyright © 2016年 旅游助手. All rights reserved.
//

#import "ForgetViewController.h"
#import "LoginViewController.h"
@interface ForgetViewController ()

@end

@implementation ForgetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"找回密码";
    
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:(UIBarButtonItemStylePlain) target:self action:@selector(rightBtnAction)];
    
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    
    [self add];
    
    // Do any additional setup after loading the view.
}

- (void)add{
    
    self.phoneNumberText = [[UITextField alloc]init];
    
    self.phoneNumberText.frame = CGRectMake(40, 84, CGRectGetWidth(self.view.frame)-40, 40);
    
    self.phoneNumberText.placeholder = @"手机号码";
    
//    [self.view addSubview:self.phoneNumberText];
    
    
    self.codeText = [[UITextField alloc]init];
    
    self.codeText.frame = CGRectMake(40, CGRectGetMaxY(self.phoneNumberText.frame), CGRectGetWidth(self.view.frame)-40, 40);
    
    self.codeText.placeholder = @"请输入绑定邮箱";
    
    [self.view addSubview:self.codeText];
    
    
    self.getBtn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    
    self.getBtn.frame = CGRectMake(self.view.frame.size.width-150, CGRectGetMaxY(self.phoneNumberText.frame)+5, 150, 30);
    
    
    self.passWordText = [[UITextField alloc]init];
    
    self.passWordText.frame = CGRectMake(40, CGRectGetMaxY(self.codeText.frame), CGRectGetWidth(self.phoneNumberText.frame), 40);
    
    self.passWordText.placeholder = @"输入新密码";
    
//    [self.view addSubview:self.passWordText];
    
    
}

- (void)rightBtnAction{
    
    [AVUser requestPasswordResetForEmailInBackground:self.codeText.text block:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            
            NSLog( @"找回成功");
                        
            [self.navigationController popViewControllerAnimated:YES];
            
        } else {
            
            NSLog(@"找回失败");
            
        }
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
